import java.util.Stack;

public class Solution {

    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for(String s: tokens){
            // 判断是数字还是字符
            if(!isOpera(s)){
                //数字，输入栈中，要将字符s转化位数字
                stack.push(Integer.parseInt(s));

            }else{
                // 是字符就先弹出两个数字,再将两个数字的运算结果放回 到栈中去
                int num2 = stack.pop();
                int num1 = stack.pop();
                switch(s){
                    case"+":
                        stack.push(num1+num2);
                        break;
                    case"-":
                        stack.push(num1-num2);
                        break;
                    case"*":
                        stack.push(num1*num2);
                        break;
                    case"/":
                        stack.push(num1/num2);
                        break;
                }
            }

        }
        return stack.pop();

    }
    public boolean isOpera(String x) {
        if(x.equals("+") || x.equals("-") ||  x.equals("*")
                || x.equals("/")) {
            return true;
        }
        return false;
    }
}
